//
//  YDMethodSwizzling.m
//  YDBASE
//
//  Created by rowena on 2019/4/22.
//  Copyright © 2019年 wuyezhiguhun. All rights reserved.
//

#import "YDMethodSwizzling.h"

//Runtime需要的头文件
#import <objc/runtime.h>

@implementation YDMethodSwizzling

+ (void)load {
    //获取类方法的Mthod
    Method methodA = class_getInstanceMethod(NSClassFromString(@"YDMethodSwizzling"), @selector(printA));
    Method methodB = class_getInstanceMethod(NSClassFromString(@"YDMethodSwizzling"), @selector(printB));

    //动态替换方法 对象方法
    method_exchangeImplementations(methodA, methodB);
    
    Method methodC = class_getClassMethod(NSClassFromString(@"YDMethodSwizzling"), @selector(printC));
    Method methodD = class_getClassMethod(NSClassFromString(@"YDMethodSwizzling"), @selector(printD));
    //动态替换 类方法
    method_exchangeImplementations(methodC, methodD);
    
}

/** 打印A */
- (void)printA {
    NSLog(@":<- wuyezhiguhun ->: YDMethodSwizzling ->: printA ->:");
}

/** 打印B */
- (void)printB {
    NSLog(@":<- wuyezhiguhun ->: YDMethodSwizzling ->: printB ->:");
}

/** 打印C */
+ (void)printC {
    NSLog(@":<- wuyezhiguhun ->: YDMethodSwizzling ->: printC ->:");
}

/** 打印D */
+ (void)printD {
    NSLog(@":<- wuyezhiguhun ->: YDMethodSwizzling ->: printD ->:");
}

@end
